home *** CD-ROM | disk | FTP | other *** search
- Subj: Re: Sorting routine.
-
-
- >Hi!
-
- >Is there a smooth way to sort 20 variables???
- >and not do like this..
-
- >--------------------------------
- >If score1_1(1)>score2_1(1)
- > Loke S7+40,Leek(S5+20)
- >endif
- >if score1_2(2)>score2_1(1)
- > loke s7+60,leek(s5+40)
- >endif
- >-------------------------------
-
- >This way makes the program very big..!
- >Any soloution anyone????
-
-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- There's loads of different methods of sorting an array.
- Most of them use loops. The quickest ones use recursion.
-
- I'm sure there's a "Sort" command in Amos. I recall ever having
- used it, but I'm sure it's there.
-
- If you can't use that, try this:
-
- cnt - loop counter
- cnt2 - second loop counter
- siz - number of array elements
- srt() - the array to sort
- tmp - a temporary var to hold a copy of one srt().
-
- For cnt=1 to siz-1
- For cnt2=cnt+1 to siz
- Rem Out of sequence?
- If srt(cnt) > srt(cnt2)
- Rem then swap the two variables.
- tmp=srt(cnt)
- srt(cnt)=srt(cnt2)
- srt(cnt2)=tmp
- Endif
- Next
- Next
-
-
- A recursive 'quick sort' would be much quicker, but isn't easy to
- understand like this one.
-
- Hope that answers your question.
-
- See ya.
-
-
-
-
- SimonC.
-
-